package com.ikun.aimian.mapper;

import com.ikun.aimian.model.dto.statistic.AppAnswerCountDTO;
import com.ikun.aimian.model.dto.statistic.AppAnswerResultCountDTO;
import com.ikun.aimian.model.entity.UserAnswer;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author xukun
 * @description 针对表【user_answer(用户答题记录)】的数据库操作Mapper
 * @createDate 2024-05-09 20:41:03
 * @Entity com.ikun.aimian.model.entity.UserAnswer
 */
public interface UserAnswerMapper extends BaseMapper<UserAnswer> {

    //    @Select("select appId, count(userId) as answerCount from user_answer\n" +
//            "    group by appId order by answerCount desc limit 10;")
//    List<AppAnswerCountDTO> doAppAnswerCount();
    @Select("SELECT ua.appId, a.appName, COUNT(ua.userId) AS answerCount "
            + "FROM user_answer ua "
            + "INNER JOIN app a ON ua.appId = a.id "
            + "GROUP BY ua.appId "
            + "ORDER BY answerCount DESC "
            + "LIMIT 10")
    List<AppAnswerCountDTO> doAppAnswerCount();



    @Select("select resultName, count(resultName) as resultCount from user_answer\n" +
            "    where appId = #{appId}\n" +
            "    group by resultName order by resultCount desc;")
    List<AppAnswerResultCountDTO> doAppAnswerResultCount(Long appId);
}





